export  default {
    convertDateFromString(dateString) {
      if (dateString) {
        var arr1 = dateString.split(" ");
        var sdate = arr1[0].split("-");
        var sdata2 = arr1[1].split(":")
        var date = new Date(sdate[0], sdate[1] - 1, sdate[2],sdata2[0], sdata2[1],sdata2[2]);
        return date;
      }
    },

    getTime(beginTime, endTime) {
      var dateDiff = endTime.getTime() - beginTime.getTime(); //时间差的毫秒数
      var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
      var leave1 = dateDiff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
      var hours = Math.floor(leave1 / (3600 * 1000)); //计算出小时数
      //计算相差分钟数
      var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
      var minutes = Math.floor(leave2 / (60 * 1000)); //计算相差分钟数
      //计算相差秒数
      var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
      var seconds = Math.round(leave3 / 1000);
      return dayDiff + "天" + hours + "小时" + minutes + "分";
    },
    getTim(time) {
      if(typeof time == "undefined" || time == null) return "未搜集数据";
      let startTime = this.convertDateFromString(time.replace(/T/, " "));
      let endTime;
      endTime = new Date();
      return this.getTime(startTime, endTime);
    },
}